package com.ogilvy.audi.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;


/**
 * Generic DAO (Data Access Object) with common methods to CRUD POJOs.
 *
 * <p>Extend this interface if you want typesafe (no casting necessary) DAO's for your
 * domain objects.
 *
 * @author <a href="mailto:bwnoll@gmail.com">Bryan Noll</a>
 * @param <T> a type variable
 * @param <PK> the primary key for that type
 */
public interface GenericDao <T, PK extends Serializable>  {

    /**
     * Generic method used to get all objects of a particular type. This
     * is the same as lookup up all rows in a table.
     * @return List of populated objects
     */
    List<T> getAll();

    /**
     * Gets all records without duplicates.
     * <p>Note that if you use this method, it is imperative that your model
     * classes correctly implement the hashcode/equals methods</p>
     * @return List of populated objects
     */
    List<T> getAllDistinct();

    /**
     * Generic method to get an object based on class and identifier. An
     * ObjectRetrievalFailureException Runtime Exception is thrown if
     * nothing is found.
     *
     * @param id the identifier (primary key) of the object to get
     * @return a populated object
     * @see org.springframework.orm.ObjectRetrievalFailureException
     */
    T get(PK id);

    /**
     * Checks for existence of an object of type T using the id arg.
     * @param id the id of the entity
     * @return - true if it exists, false if it doesn't
     */
    boolean exists(PK id);

    /**
     * Generic method to save an object - handles both update and insert.
     * @param object the object to save
     * @return the persisted object
     */
    T save(T object);

    /**
     * Generic method to delete an object based on class and id
     * @param id the identifier (primary key) of the object to remove
     */
    void remove(PK id);

    /**
     * Find a list of records by using a named query
     * @param queryName query name of the named query
     * @param queryParams a map of the query names and the values
     * @return a list of the records found
     */
    List<T> findByNamedQuery(String queryName, Map<String, Object> queryParams);


    /**
          * 返回指定sql的分页记录
          * @param firstRecord
          * @param page_size
          * @param sql
          * @return
          */
//    @Deprecated
//     public List<T> getRecords(int firstRecord, int page_size,  String sql,String sDate,String eDate);

       /**
        * 返回指定SQL的分页记录，支持多个时间参数
        * @param firstRecord
        * @param page_size
        * @param sql
        * @param dateSet
        * @return
        */
        public List<T> getRecords(final int firstRecord,final  int page_size, final String sql,final Collection<String> dateSet) ;

         /**
          * 返回指定条件的记录数目
          * @param sql
          * @return
          */
         @Deprecated
         public Integer getRecordSizeBySql(String sql, String sDate, String eDate);
               /**
          * 返回指定条件的记录数目
          * @param sql
          * @return
          */
       public Integer getRecordSizeBySql(final String sql,Collection<String> dateSet)   ;
         /**
          * 返回指定sql的不分页记录
          * @param sql
          * @return
          */
         public List<T> getRecords(final String sql,Collection<String> dateSet);

       public List<T> getAllRecords(final String sql);


       public int batchUpdate(final String hql,Collection<String> dateSet);

        public void  executeByNativeSQL(final String nativeSql);



       /**
        * 批量存储
        * @param sets
        */
         public   void batchInsertSet(final Set<T> sets);

       /**
        * 删除给定的对象
        * @param entity
        */
        public   void delete(Object entity);

       /**
        * 获取 分组统计后的 记录总数
        * @param hql
        * @return
        */
           public Integer getCountGroupSize(final String hql,Collection<String> dateSet);

       /**
        * 执行SQL语句
        * @param hql
        * @param dateTime  时间
        * @param start       开始记录数
        * @param end       结束记录数
        * @return
        */

        public int executeHql(final String hql,final java.sql.Date dateTime,final Integer start,final Integer end);

}